package com.D5Power.Editor.EditorWindow
{
	import com.D5Power.Editor.MapShower;
	
	import flash.events.Event;
	import flash.filesystem.File;
	import flash.net.FileFilter;
	
	import org.aswing.JButton;
	import org.aswing.JLabel;
	import org.aswing.JPanel;
	import org.aswing.JTextField;
	import org.aswing.SoftBoxLayout;
	import org.aswing.ext.Form;

	public class MapConf extends D5EditorWin
	{
		private var main:JPanel;
		
		private var _fileName:JTextField;
		private var _scriptPath:JTextField;
		
		private const MUSIC_PATH:String = 'asset/music/';
		private const SCRIPT_PATH:String = 'script/';
		
		public function MapConf(owner:D5RpgEditor)
		{
			super(owner);
		}
		
		override protected function init(mode:uint=0):void
		{
			_box = new Form();
			main = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS));
			
			_scriptPath = new JTextField(MapShower.MusicPath,8);
			
			var lab2:JLabel = new JLabel("脚本文件：");
			var bt2:JButton = new JButton('选择');
			bt2.addActionListener(openScript);
			
			_fileName = new JTextField(MapShower.ScriptPath,8);
			var lab1:JLabel = new JLabel('背景音乐：');
			var bt1:JButton = new JButton('选择');
			bt1.addActionListener(openMusic);
			
			_box.addRow(lab2,_scriptPath,bt2);
			_box.addRow(lab1,_fileName,bt1);
			
			main.append(_box);
			_box.setSizeWH(200,260);
			getContentPane().append(main);
			super.init();
		}
		
		private function openMusic(e:Event):void
		{
			var file_open:File = File.applicationDirectory.resolvePath(MUSIC_PATH);
			file_open.browseForOpen('选择音乐文件', [new FileFilter('音乐', '*.mp3' )] );
			file_open.addEventListener(Event.SELECT,onOpenMusic);
		}
		
		private function onOpenMusic(e:Event):void
		{
			var file:File = e.target as File;
			
			_fileName.setText(MUSIC_PATH+file.name);
		}
		
		private function openScript(e:Event):void
		{
			var file_open:File = File.applicationDirectory.resolvePath(MUSIC_PATH);
			file_open.browseForOpen('选择脚本文件', [new FileFilter('D5GameScript', '*.d5' )] );
			file_open.addEventListener(Event.SELECT,onOpenScript);
		}
		
		private function onOpenScript(e:Event):void
		{
			var file:File = e.target as File;
			_scriptPath.setText(SCRIPT_PATH+file.name);
		}
		
		override protected function onSubmit(e:Event):void
		{
			MapShower.MusicPath = _fileName.getText();
			MapShower.ScriptPath = _scriptPath.getText();
			super.onSubmit(e);
		}
	}
}